import 'package:flutter/material.dart';
import 'package:hao_ke/utils/dio_http.dart';
import 'package:hao_ke/pages/utils/scoped_model_helper.dart';
import '../pages/auth/auth.dart';

class ProjectWidget extends StatefulWidget {
  const ProjectWidget({super.key});

  @override
  State<ProjectWidget> createState() => _ProjectWidgetState();
}

class _ProjectWidgetState extends State<ProjectWidget> {

  List<DropdownMenuItem> items = [];

  @override
  Widget build(BuildContext context) {
    _getStore();
    return Container(
      child: DropdownButtonFormField(
        hint: Text("请选择项目"),
        icon: Icon(Icons.production_quantity_limits,color: Colors.blue,),
        items: items,
        onChanged: (value) {},
      )
    );
  }


  _getStore() async {
    var storeList = await DioHttp().init(context, ScopedModelHelper.getModel<AuthModel>(context).token).get("/oms/project/?available=1&special=false");
    setState(() {
      items = [];
      storeList.forEach((element) {
        items.add(DropdownMenuItem(
          child: Text(element['name']+"("+element['price'].toString()+")"),
          value: element['pkid'],
        ));
      });
    });
  }
}
